﻿#include "ToolBarZoom.h"
#include "DisplayWidget.h"

#include <QLabel>
#include <QSpinBox>
#include <QCheckBox>

ToolBarZoom::ToolBarZoom(const QString &title, QWidget *parent)
    :QToolBar(title, parent)
{
    setIconSize(QSize(32, 32));
    initContent();
    centerWidget = nullptr;
}

void ToolBarZoom::attach(DisplayWidget *widget)
{
    centerWidget = widget;
    connect(spinBox, SIGNAL(valueChanged(int)), centerWidget, SLOT(setZoomFactorPCT(int)));
    connect(checkBox, SIGNAL(toggled(bool)), centerWidget, SLOT(showCross(bool)));

    spinBox->setValue(60);
}

void ToolBarZoom::initContent()
{
    setWindowTitle("Image Zoom Toolbar");
    setObjectName(QStringLiteral("ToolBarZoom"));

    QLabel *label = new QLabel(QStringLiteral("显示比例: "), this);
    addWidget(label);

    spinBox = new QSpinBox;
    spinBox->setSuffix(" %");
    spinBox->setRange(10, 1000);
    spinBox->setValue(100);
    spinBox->setSingleStep(10);
    addWidget(spinBox) ;
    addSeparator();
    checkBox = new QCheckBox(QStringLiteral("+"));
    addWidget(checkBox) ;
    checkBox->setChecked(true);
}

ToolBarZoom::ToolBarZoom(QWidget *parent)
    :QToolBar(parent)
{
    setIconSize(QSize(32, 32));

    initContent();
    centerWidget = nullptr;
}

double ToolBarZoom::getZoom()
{
    return (double)spinBox->value() / 100;
}
